package org.jeecg.modules.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.system.entity.ProductionStatusEntity;
import org.jeecg.modules.system.service.ProductionStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ProductionStatus")
public class ProductionStatusController {

    @Autowired
    ProductionStatusService service;
    /**
     * 查询所有生产状态
     */
    @GetMapping("/list")
    public Result<?> ProductionStatusList(
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            String code,
            String category

    ){
        Page<ProductionStatusEntity> page=new  Page<ProductionStatusEntity>(pageNo, pageSize);
        IPage<ProductionStatusEntity> pageList=service.getProductionStatusList(page,code,category);
        return Result.ok(pageList);
    }

    /**
     * 新增生产状态
     */
    @PostMapping("/addProductionStatus")
    public Result<?> addProductionStatus(
         @RequestBody   ProductionStatusEntity entity
    ){
        try {

           int conut=service.addProductionStatus(entity);

            return  Result.ok("新增成功");
        }catch (Exception e){
            e.printStackTrace();
            return  Result.error("新增失败");
        }
    }


    /**
     * 编辑
     */

    @PostMapping("/updateProductionStatus")
    public Result<?> updateProductionStatus(
            @RequestBody   ProductionStatusEntity entity
    ){
        try {

            int conut=service.updateProductionStatusdetail(entity);
            return  Result.ok("修改成功");
        }catch (Exception e){
            e.printStackTrace();
            return  Result.error("修改失败");
        }
    }


    /**
    删除生产状态
     */
    @GetMapping("/deleteProductionStatus")
    public Result<?> deleteProductionStatus(
            @RequestParam(name = "id") int id
    ){
        int count=service.deleteProductionStatus(id);
        return  Result.ok("删除成功");
    }

    /**
     * 修改状态
     */
    @GetMapping("/updatestatus")
    public Result<?> updateProductionStatus(
            @RequestParam(name = "id") int id,
            @RequestParam(name = "status") int status
    ){
        int count=service.updateProductionStatus(id,status);
        return  Result.ok("删除成功");
    }


    /**
     * 编辑时候的查看详情
     */
   @GetMapping("/detail")
   public Result<?> getdetail(
           @RequestParam(name = "id") int id){
       ProductionStatusEntity entity=service.getdetail(id);
       return  Result.ok(entity);
   }
}
